package satir.command;

import java.util.ArrayList;
import java.util.Scanner;

import satir.SatirGame;
import satir.player.Player;

/**
 * Enter Player number.
 * 
 * @version 2.0 March 2012
 * @author Bill Chan
 */

public class EnterPlayerNumCmd implements Command {
	
	/** The satir game. */
	private SatirGame satirGame;
	
	/**
	 * Instantiates a new enter player num cmd.
	 *
	 * @param satirGame the satir game
	 */
	public EnterPlayerNumCmd(SatirGame satirGame){
		this.satirGame = satirGame;
	}
	
	/* (non-Javadoc)
	 * @see stair.command.BoardCmd#execute()
	 */
	public void execute() {
		Scanner scanner= new Scanner(System.in);		
		String temp;
		int playerNumber;
		
		do {
			System.out.println("Input the number of players:(2-6)");
			temp=scanner.next();
			if(temp.charAt(0)>='2' && temp.charAt(0)<='6'){
				break;
			}
			System.out.println("Wrong input");
		}while(true);
		playerNumber=temp.charAt(0)-'0';
		satirGame.setNumOfPlayer(playerNumber);
		System.out.println("There are " + playerNumber + " players");
		ArrayList<Player> players = new ArrayList<Player>();
		for (int i = 0; i < playerNumber; i++) {
			players.add(new Player());
		}
		satirGame.setArrayListPlayer(players);
	}
}